#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int t,n;
int a[N],b[N],c[N],d[N];
int k,ans;
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		memset(d,0,sizeof(d));
		k=1,ans=0;
		int t1=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		for(int i=1;i<=n;i++){
			k*=2;
		}
		for(int i=0;i<k;i++){
			int p=i,k1=0;
			k1++;
			d[k1]=p%2;
			p/=2;
			for(int j=1;j<=k1;j++){
				b[n-j+1]=d[j];
			}
			for(int j=1;j<=n;j++){
				for(int e=j-1;e>=1;e--){
					if(b[e]==b[j] && a[e]==a[j]) {
						c[j]=a[j];
						break;
					}
				}
				t1+=c[j];
			}
		}
		ans=max(ans,t1);
		printf("%d\n",ans);
	}
	return 0;
}
